################
#PSRM: Explaining Support for Redistribution: Social Insurance Systems and Fairness
#
#Observational Analysis: ESS
# Table B 3
#
#Verena Fetscher
#July 2022
####################

####################
# Load packages
####################

library(tidyverse)
library(xtable)

####################
# Load data
####################

load("DataFile_07_Replacement.Rda")
load("replacement.Rda")



##########################
#Illustrations: Single earner
##########################


replacement%>%
  filter(famtype=="single") %>%
  group_by(Country) %>%
  summarise(RR_100 = mean(RR[AW==100],na.rm=T),
            RR_50 = mean(RR[AW==50],na.rm=T),
            RR_200 = mean(RR[AW==200],na.rm=T)) -> df


min<-rbind(min(df$RR_50),min(df$RR_100),min(df$RR_200))
mean<-rbind(mean(df$RR_50),mean(df$RR_100),mean(df$RR_200))
max<-rbind(max(df$RR_50),max(df$RR_100),max(df$RR_200))

df_table<-cbind(min,mean,max)
rownames(df_table)<-c("AW 50%", "AW 100%", "AW 200%")
colnames(df_table)<-c("min", "mean", "max")


##########################
#Produces Table B.3: Single person, no children.
##########################
xtable(df_table, caption="Single person, no children.")



